package cn.pfz.Service.impl;

import cn.pfz.Service.IRoleSerives;
import cn.pfz.domain.Permission;
import cn.pfz.domain.Role;
import cn.pfz.mapper.RoleMapper;
import cn.pfz.query.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IRoleSerivesimpl implements IRoleSerives {

    @Autowired
    private RoleMapper roleMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Role record) {
        return roleMapper.insert(record);
    }

    @Override
    public Role selectByPrimaryKey(Long id) {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Role> selectAll() {
        return roleMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Role record) {
        return roleMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<Role> list(QueryObject qo) {
        //通过pageHelper进行设置分页及排序
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"id asc");
        //在Sql中不需要limit
        List<Role> Employees = roleMapper.selectRusult(qo);
        PageInfo<Role> PageInfo = new PageInfo(Employees);
        return PageInfo;
    }

    @Override
    public List<Role> selectByEmployee(Long id) {
        return roleMapper.selectByEmployee(id);
    }

    @Override
    public List<Permission> selectByRole(Long id) {
        return roleMapper.selectByRole(id);
    }

    @Override
    public List<String> selectRoleByEmployeeId(Long id) {

        return roleMapper.selectRoleByEmployeeId(id);

    }
}
